package com.app.cpcap.dao;

import org.hibernate.Session;
import org.hibernate.Transaction;

import br.com.caelum.vraptor.ioc.Component;

import com.app.cpcap.bean.Empresa;
import com.app.cpcap.bean.Feriado;
import com.app.cpcap.bean.Grupo;
import com.app.cpcap.bean.Orgao;
import com.app.cpcap.bean.Registro;
import com.app.cpcap.bean.Usuario;
import com.app.cpcap.hibernate.HibernateConnectionFactory;

@Component
public class DaoFactory {
	private final Session session;
	private Transaction transaction;

	public DaoFactory() {
		session = HibernateConnectionFactory.getSession();
	}

	public void beginTransaction(){
		transaction = session.beginTransaction();
	}

	public void commit(){
		transaction.commit();
		transaction = null;
	}

	public void rollBack(){
		transaction.rollback();
		transaction = null;
	}
	
	public EmpesaDao getEmpresa(){
		return new EmpesaDao(Empresa.class, session);
	}
	public RegistroDao getRegistro(){
		return new RegistroDao(Registro.class, session);
	}
	public FeriadoDao getFeriado(){
		return new FeriadoDao(Feriado.class, session);
	}
	public OrgaoDao getOrgao(){
		return new OrgaoDao(Orgao.class, session);
	}
	public GrupoDao getGrupo(){
		return new GrupoDao(Grupo.class, session); 
	}
	public UsuarioDao getUsuario(){
		return new UsuarioDao(Usuario.class, session); 
	}
}
